package com.zhsq.zlc.util;

import com.zhsq.zlc.entity.UserAuthorityEntity;

import java.util.List;

public class MenuUtil {
	
	public static String getNavMenu(List<UserAuthorityEntity> list){
		StringBuffer navMenuHtml = new StringBuffer();
		if(list!=null && list.size()>0){
			for(UserAuthorityEntity authority:list){
				navMenuHtml.append("<li id=\""+authority.getUrl()+"\">");
				if(authority.getChildMenus()!=null && authority.getChildMenus().size()>0 ){
					navMenuHtml.append("<a id=\"a_"+authority.getUrl()+"\" href=\"#\"  onclick=\"showHideChildMenu(this)\"><i class=\"fa fa-"+authority.getIcon()+"\"></i> <span class=\"nav-label\">"+authority.getName()+"</span><span class=\"fa arrow\"></span></a>"+makeSideChildMenu(authority.getChildMenus(),authority.getUrl()));
				}else{
					navMenuHtml.append("<a href=\""+authority.getUrl()+"\"><i class=\"fa fa-"+authority.getIcon()+"\"></i> <span class=\"nav-label\">"+authority.getName()+"</span></a>");
				}
				navMenuHtml.append("</li>");
			}
		}
		return navMenuHtml.toString().replaceAll("null", "");
	}

	public static String makeSideChildMenu(List<UserAuthorityEntity> list ,String url){
		StringBuffer childNavMenuHtml = new StringBuffer();
		if(list!=null && list.size()>0) {
			childNavMenuHtml.append("<ul id=\"ul_"+url+"\" class=\"nav nav-second-level\">");
			for (UserAuthorityEntity authority : list) {
				String[] urlID=authority.getUrl().split("_");
				childNavMenuHtml.append("<li id=\""+urlID[0]+"\"><a href=\""+authority.getUrl()+"\"><i class=\"fa fa-"+authority.getIcon()+"\"></i>"+authority.getName()+"</a></li>");
			}
			childNavMenuHtml.append("</ul>");
		}
		return childNavMenuHtml.toString().replaceAll("null", "");
	}
}